package a_doubleWrite;

/**
 415. 字符串相加
 给定两个字符串形式的非负整数 num1 和num2 ，计算它们的和。
    998    899
 +23786    68732
  24784    48742
 * @author: luolidong
 * @create: 2021-07-17 19:37
 * @version: 1.0
 */
public class L415 {
    public String addStrings(String num1, String num2) {
        String num11 = new StringBuilder(num1).reverse().toString();
        String num22 = new StringBuilder(num2).reverse().toString();
        StringBuilder sb = new StringBuilder();
        int i=0;
        int pre=0;
        while (i<num11.length()||i<num22.length()){
            int n1=i<num11.length()? num11.charAt(i)-'0':0;
            int n2=i<num22.length()? num22.charAt(i)-'0':0;
            int n3=n1+n2+pre;
            pre=(n3)/10;
            sb.append((n3)%10);
            i++;
        }
        if(pre==1) sb.append(1);
        return sb.reverse().toString();
    }

    public static void main(String[] args) {
        L415 l415 = new L415();
        String s = l415.addStrings("998", "23786");
        System.out.println(s);
    }
}
